/**
 * 用于测试功能
*/

#include"commutils.h"

int main(){
    /*vector<folderiNode> workpath;
    workpath.push_back(readFolderInode(0));
    workpath.push_back(readFolderInode(0));
    cout<<"path:"<<getStringPath(workpath)<<endl;*/
    void *shm = NULL;
    int shmid;
    struct shared_mem_st *shared = NULL;
    //创建共享内存
    shmid = shmget((key_t)MEMKEY, sizeof(struct shared_mem_st), 0666|IPC_CREAT);
    if(shmid == -1)
    {
        fprintf(stderr, "shmget failed\n");
        exit(EXIT_FAILURE);
    }
    //将共享内存连接到当前进程的地址空间
    shm = shmat(shmid, (void*)0, 0);
    if(shm == (void*)-1)
    {
        fprintf(stderr, "shmat failed\n");
        exit(EXIT_FAILURE);
    }
    printf("Memory attached at 0x%X\n", (long int)shm);
    //设置共享内存
    shared = (struct shared_mem_st*)shm;

    string line;
    getline(cin,line);
    strcpy(shared->cmd, line.c_str());
    cout<<"in shared:"<<shared->cmd<<endl;

    //把共享内存从当前进程中分离
    if(shmdt((void*)shared) == -1)
    {
        fprintf(stderr, "shmdt failed\n");
        exit(EXIT_FAILURE);
    }
    //删除共享内存  
    if(shmctl(shmid, IPC_RMID, 0) == -1)
    {
        fprintf(stderr, "shmctl(IPC_RMID) failed\n");
        exit(EXIT_FAILURE);
    }
    /*map<int,int> m;
    m.insert(pair<int,int>(1,1));
    m.insert(pair<int,int>(2,1));
    m.insert(pair<int,int>(3,1));
    m.insert(pair<int,int>(5,1));
    cout<<m.find(2)->second<<endl;
    m.find(2)->second++;
    cout<<m.find(2)->second<<endl;
    cout<<m.count(1)<<m.count(4)<<endl;
    doCheck();*/
    /*cout << "fileinodesize:"<<sizeof(fileiNode)<<endl;
    cout<<"foldinodesize:"<<sizeof(folderiNode)<<endl;
    cout<<"itemsize:"<<sizeof(FoldItem)<<endl;*/
    //fstream disk(FNAME, ios::binary|ios::in|ios::out);
    //DiskStatus ds=getDiskStatus();
    //cout<<ds.toString()<<endl;
/*
    string bin=byteChar2Bin('?');
    char* bytebin=(char*)bin.data();
    byteBin2Char(bytebin);

    string r=readStr(0x50, 6);
    cout<<r<<endl;

    
    cout<<sizeof(int)<<' '<<sizeof(char);

    char a[]="lbcc!";
    writeStr(0x50, a, strlen(a));
*/
    /*int t=getIntTime();
    cout <<"intTime:\t"<<t<<endl;
    cout <<"strTime:\t"<<timeToString(t)<<endl;
    return 0;*/
    //formatDisk();
    //readInodeBmap(0);
    //readFblkBmap(0);
    //cout<<castChar2Int(inodeBmap[0])<<endl;
    //cout<<castChar2Bin(inodeBmap[0])<<endl;
    //for(int i =0; i<10; ++i)writeBitMap(i,i%2);
    /*
    loadBitMap();
    int i=KB-1;
    while(++i<KB+20){
        cout <<readBitMap(i);
    }cout<<endl;*/
    //cout<<"'"<<bitMap[12799]<<"'"<<endl;
    //storeBitMap();
    
    /*fileiNode n;
    n.nodeNo=3;
    n.fileSize=0;
    n.protectCode=(char)63;
    n.createTime=getIntTime();
    n.lastCatTime=0;
    cout<<n.toString()<<endl;
    n.addBlock(0);
    cout<<n.toString()<<endl;
    n.addBlock(1);
    cout<<n.toString()<<endl;*/
    
    //writeFileInode(n,0);
    /*char a[KB]="66666666";
    saveBlock(a,1);
    char b[KB];
    getBlock(b,1);*/
    /*
    char b[KB]{};
    writeFileInode2Blk(b, n);
    saveBlock(b, 0);
    */
    //castChar2Int(n.fileSize);
    /*clearDisk();
    folderiNode n;
    n.nodeNo=0;
    string fname="root";
    strcpy(n.folderName, fname.c_str());
    n.folderSize=0;
    n.protectCode=(char)63;
    n.createTime=874564000;
    n.lastCatTime=874564312;
    
    n.addSubItem(0,"alohaaaaaaaaa.txt");
    cout<<n.toString()<<endl;
    n.addSubItem(1,"guide.txt");
    cout<<n.toString()<<endl;

    writeFolderInode(n, 0);
    cout<<n.toString()<<endl;*/
    
    /*formatDisk();
    fileiNode n=readFileInode(2);
    cout<<n.toString(1)<<endl;
    folderiNode nn=readFolderInode(0);
    cout<<nn.toString(1)<<endl;*/

    /*char buff[KB]{};
    getBlock(buff, 16);
    for(int i=4; i<8; ++i){
        cout<<buff[i]<<'-';
    }
    cout<<endl;*/
    /*char byte[]="10011";
    int a = castBin2Char(byte);
    cout<< (a&(1<<2)) <<endl;*/
    /*string s="TGG2.txt";
    folderiNode f=readFolderInode(0);
    fileiNode file;
    if(getFileByPath(f,file,s))
        cout<<file.toString();*/
    return 0;
} 